<?php

class Image(){
	//内存中的图片
	private $image;
	//图片的信息
	private $info;

	/*
	
	 */
	public function __construct($src){
		$info = getimagesize($src);
		$this->info=array(
				'width'=>$info['0'],
				'height'=>$info['1'],
				'type'=>image_type_to_extension($info['2'],false),
				'mime'=>$info['mime']
			);
		$fun = "imagecreatefrom{$this->info['type']}";
		$this->image = $fun($src);
	}




	/**
	 * 操作图片
	 */
	public function Thumb($width,$height){
		$image_thumb = imagecreatetruecolor($width,$height);
		imagecopyresampled($image_thumb, $this->image, 0, 0, 0, 0, $width,$height, $this->info['width'], $this->info['height']);
		imagedestroy($this->image);
		$this->image = $image_thumb;
	}

	/**
	 * 从浏览器中输出
	 */
	public function show(){
		header("Content-type:".$this->info['mime']);
		$funs = "image{$this->info['type']}";
		$funs($this->image);
	}



	/**
	 * 把图片保存到硬盘里
	 */
	public function save($newName){
		$funs = "image{$this->info['type']}";
		$funs($this->image,$newName.'.'.$this->info['type']);
	}


	/**
	 * 销毁图片
	 */
	public function __destruct(){
		imagedestroy($this->image);
	}
}
?>